home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac: Not for Sale / Another.not.for.sale (Australia).iso / fade into you / getting there / TCP⁄PPP⁄SLIP / TCP⁄IP Scripting Addition 1.1.2 / Examples 1.2 / Text Versions / Send Mail (text) < prev   
Text File  |  1994-09-18  |  3KB  |  87 lines

  1. (*
  2. Send Mail Script 1.1
  3. Copyright © 1994 by Atul Butte. All Rights Reserved.
  4.  
  5. Sends a test e–mail message to your account. Improvements by Roel Vertegaal.
  6. *)
  7.  
  8. on run
  9.     set dialog_response to (display dialog "Enter the name of the machine where you read e-mail" default answer "")
  10.     if (button returned of dialog_response ≠ "OK") then
  11.         return
  12.     else
  13.         set email_host to text returned of dialog_response
  14.     end if
  15.     
  16.     set dialog_response to (display dialog "Enter your e-mail address on " & email_host default answer "")
  17.     if (button returned of dialog_response ≠ "OK") then
  18.         return
  19.     else
  20.         set email_address to text returned of dialog_response
  21.     end if
  22.     
  23.     set dialog_response to (display dialog "Enter a subject for this message" default answer "")
  24.     if (button returned of dialog_response ≠ "OK") then
  25.         return
  26.     else
  27.         set email_subject to text returned of dialog_response
  28.     end if
  29.     
  30.     send_message(email_host, email_address, email_subject)
  31. end run
  32.  
  33. on send_message(email_host, email_address, email_subject)
  34.     set LF to ASCII character (10)
  35.     set CR to return
  36.     set CRLF to CR & LF
  37.     
  38.     set sss to (tcp connect to host email_host port 25)
  39.     try
  40.         readresponse(sss)
  41.         tcp write data "mail from: applescript@[" & local host of (tcp status stream sss) & "]" & return ¬
  42.             stream sss using ISO88591
  43.         readresponse(sss)
  44.         tcp write data "rcpt to: " & email_address & return ¬
  45.             stream sss using ISO88591
  46.         readresponse(sss)
  47.         tcp write data "data" & return stream sss using ISO88591
  48.         readresponse(sss)
  49.         tcp write data "To: " & email_address & "@" & email_host & return stream sss using ISO88591
  50.         tcp write data "Subject: " & email_subject & return stream sss using ISO88591
  51.         tcp write data "This is a test message from AppleScript." & return stream sss using ISO88591
  52.         tcp write data "." & return stream sss using ISO88591
  53.         readresponse(sss)
  54.         tcp close stream sss
  55.         return
  56.     on error msg number num
  57.         tcp close stream sss
  58.         display dialog "Error: " & msg & " " & num
  59.     end try
  60. end send_message
  61.  
  62. on readresponse(sstream)
  63.     set LF to ASCII character (10)
  64.     set continuechar to "-"
  65.     set wholemessage to ""
  66.     repeat until continuechar = " "
  67.         repeat until (tcp ahead characters LF stream sstream)
  68.         end repeat
  69.         set readline to (tcp read until characters LF stream sstream using ISO88591)
  70.         set scan to (scanline(readline))
  71.         set continuechar to item 2 of scan
  72.         set wholemessage to wholemessage & " " & item 3 of scan
  73.     end repeat
  74.     set errorCode to item 1 of scan as integer
  75.     if (errorCode ≥ 400) then
  76.         display dialog "Error: " & wholemessage
  77.         error wholemessage number errorCode
  78.     end if
  79. end readresponse
  80.  
  81. -- Matches lines like:
  82. -- 250 test... Sender ok
  83.  
  84. on scanline(lline)
  85.     return {characters 1 through 3 of lline as string, character 4 of lline as string, ¬
  86.         characters 5 through end of lline as string}
  87. end scanline